def is_prime(a):
    if a == 1:
        return True
    if a <= 3:
        return True
    if a % 2 == 0 or a % 3 == 0:
        return False
    i = 5
    while i * i <= a:
        if a % i == 0 or a % (i + 2) == 0:
            return False
        i += 6
    return True


def fp(a):
    if is_prime(a):
        return a

    step = 1
    while True:
        if is_prime(a - step):
            return a - step
        if is_prime(a + step):
            return a + step
        step += 1


def cn(words):
    sp = {
        "zero": 0,
        "one": 1,
        "two": 2,
        "three": 3,
        "four": 4,
        "five": 5,
        "six": 6,
        "seven": 7,
        "eight": 8,
        "nine": 9,
    }

    try:
        num = int("".join(str(sp[word]) for word in words))
        if 0 <= num <= 9999999999999999999:
            return num
        else:
            return False
    except KeyError:
        return False


words = input().split()
num = cn(words)
if num == False:
    print("Wrong input")
else:
    print(fp(num))